/*
 * Copyright 2020 Mike Penz
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mikepenz.iconics.typeface.library.community.material;

import ohos.agp.text.Font;
import ohos.app.Context;
import ohos.utils.Pair;

import com.mikepenz.iconics.typeface.FontCreator;
import com.mikepenz.iconics.typeface.IIcon;
import com.mikepenz.iconics.typeface.ITypeface;

import java.util.ArrayList;
import java.util.List;

/**
 * 图标库
 *
 * @since 2021-06-05
 */
public class CommunityMaterial implements ITypeface {
    private static final CommunityMaterial INSTANCE = new CommunityMaterial();

    private CommunityMaterial() {
    }

    /**
     * 获取实例
     *
     * @return 实例对象
     */
    public static CommunityMaterial getInstance() {
        return INSTANCE;
    }

    @Override
    public String getFontRes() {
        return "community_material_font_v5_8_55.ttf";
    }

    @Override
    public Font getRawTypeface(Context context) {
        return FontCreator.createFont(context, getFontRes());
    }

    @Override
    public List<Pair<String, Character>> getCharacters() {
        List<Pair<String, Character>> pairs = new ArrayList<>();
        for (Icon icon : Icon.values()) {
            pairs.add(new Pair<>(icon.getName(), icon.getCharacter()));
        }
        for (Icon2 icon : Icon2.values()) {
            pairs.add(new Pair<>(icon.getName(), icon.getCharacter()));
        }
        for (Icon3 icon : Icon3.values()) {
            pairs.add(new Pair<>(icon.getName(), icon.getCharacter()));
        }
        for (Icon4 icon : Icon4.values()) {
            pairs.add(new Pair<>(icon.getName(), icon.getCharacter()));
        }
        return pairs;
    }

    @Override
    public String getMappingPrefix() {
        return "cmd";
    }

    @Override
    public String getFontName() {
        return "Community Material Design";
    }

    @Override
    public String getVersion() {
        return "5.3.45.1";
    }

    @Override
    public int getIconCount() {
        return getCharacters().size();
    }

    @Override
    public List<String> getIcons() {
        List<Pair<String, Character>> pairs = getCharacters();
        List<String> list = new ArrayList<>();
        for (Pair<String, Character> pair : pairs) {
            list.add(pair.f);
        }
        return list;
    }

    @Override
    public String getAuthor() {
        return "Templarian / Community / Google";
    }

    @Override
    public String getUrl() {
        return "http://materialdesignicons.com/";
    }

    @Override
    public String getDescription() {
        return "Material Design Icons are the official open-source icons featured in the Google "
            + "Material Design specification.";
    }

    @Override
    public String getLicense() {
        return "Templates - Free, Community Icons - SIL Open Font License 1.1, Google Material "
            + "Design Icons: Attribution 4.0 International";
    }

    @Override
    public String getLicenseUrl() {
        return "https://raw.githubusercontent.com/Templarian/MaterialDesign/master/license.txt";
    }

    @Override
    public IIcon getIcon(String key) {
        try {
            return Icon.valueOf(key);
        } catch (IllegalArgumentException e) {
            try {
                return Icon2.valueOf(key);
            } catch (IllegalArgumentException e2) {
                try {
                    return Icon3.valueOf(key);
                } catch (IllegalArgumentException e3) {
                    return Icon4.valueOf(key);
                }
            }
        }
    }
}
